<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8" />
        <title>onresourcetimingbufferfull callback of resource timing</title>
        <script>
            var count = 0;
            var supportBufferControlInterface = false;
            if (performance && performance.setResourceTimingBufferSize)
                supportBufferControlInterface = true;

            function buffer_full_call_back()
            {
                count++;
            }
        </script>
        <link rel="author" title="Intel" href="http://www.intel.com/" />
        <link rel="help" href="http://www.w3.org/TR/resource-timing/#performanceresourcetiming"/>
        <script src="/resources/testharness.js"></script>
        <script src="/resources/testharnessreport.js"></script>
        <script src="/webperf/tests/resources/webperftestharness.js"></script>
        <script>
            setup({ explicit_done: true });            
            test_namespace();
            function onload_test()
            {
                if (!supportBufferControlInterface) {
                    test_true(false, "performance.setResourceTimingBufferSize() interface is supported!");
                    done();                
                    return;
                } 
 
                performance.setResourceTimingBufferSize(3);
                performance.setResourceTimingBufferSize(2);
                test_equals(count, 2, "onresourcetimingbufferfull should be invoked once the buffer is shrunk to size which is less than or equal to current entry number!");
                done();                
            }
        </script>
    </head>
    <body onload="onload_test();">
        <h1>Description</h1>
        <p>This test validates the functionality of onresourcetimingbufferfull in resource timing.</p>
        <script>
            if (performance && performance.clearResourceTimings) {
                performance.clearResourceTimings();
                performance.addEventListener("resourcetimingbufferfull", buffer_full_call_back);
                for (var i = 1; i <= 3; i++) {
                    var image = document.createElement("img");
                    image.src = "/webperf/tests/resources/generate_resource.php?type=image&id=" + i;
                }
            }
        </script>
        <div id="log"></div>
    </body>
</html>
